home *** CD-ROM | disk | FTP | other *** search
/ Enter 2004 January / enter-2004-01.iso / files / maxima-5.9.0.exe / {app} / info / maxima.info-12 < prev    next >
Encoding:
GNU Info File  |  2003-02-09  |  42.0 KB  |  1,010 lines

  1. This is maxima.info, produced by makeinfo version 4.1 from maxima.texi.
  2.  
  3.    This is a Texinfo Maxima Manual
  4.  
  5.    Copyright 1994,2001 William F. Schelter
  6.  
  7. START-INFO-DIR-ENTRY
  8. * Maxima: (maxima).     A computer algebra system.
  9. END-INFO-DIR-ENTRY
  10.  
  11. 
  12. File: maxima.info,  Node: Definitions for Miscellaneous Options,  Prev: SHARE,  Up: Miscellaneous Options
  13.  
  14. Definitions for Miscellaneous Options
  15. =====================================
  16.  
  17.  - Variable: ALIASES
  18.      default: [] atoms which have a user defined alias (set up by the
  19.      ALIAS, ORDERGREAT, ORDERLESS functions or by DECLAREing the atom a
  20.      NOUN).
  21.  
  22.  - Variable: ALLSYM
  23.      default: [TRUE] - If TRUE then all indexed objects are assumed
  24.      symmetric in all of their covariant and contravariant indices. If
  25.      FALSE then no symmetries of any kind are assumed in these indices.
  26.      Derivative indices are always taken to be symmetric.
  27.  
  28.  - declaration: ALPHABETIC
  29.      Adds to MACSYMA's alphabet which initially contains the letters
  30.      A-Z, % and _.  Thus, DECLARE("~",ALPHABETIC) enables NEW~VALUE to
  31.      be used as a name.
  32.  
  33.  
  34.  - Function: APROPOS (string)
  35.      takes a character string as argument and looks at all the MACSYMA
  36.      names for ones with that string appearing anywhere within them.
  37.      Thus, APROPOS(EXP); will return a long list of all the flags and
  38.      functions which have EXP as part of their names, such as EXPAND,
  39.      EXP, EXPONENTIALIZE.  Thus if you can only remember part of the
  40.      name of something you can use this command to find the rest of the
  41.      name.  Similarily, you could say APROPOS(TR_); to find a list of
  42.      many of the switches relating to the TRANSLATOR (most of which
  43.      begin with TR_).
  44.  
  45.  
  46.  - Function: ARGS (exp)
  47.      returns a list of the args of exp.  I.e. it is essentially
  48.      equivalent to
  49.           SUBSTPART("[",exp,0)
  50.      Both ARGS and SUBSTPART depend on the setting of INFLAG.
  51.  
  52.  
  53.  - Function: DUMMY (i1,i2,...)
  54.      will set each index i1,i2,... to name of the form !n where n is a
  55.      positive integer.  This guarantees that dummy indices which are
  56.      needed in forming expressions will not conflict with indices
  57.      already in use.  COUNTER[default 1] determines the numerical
  58.      suffix to be used in generating the next dummy index.  The prefix
  59.      is determined by the option DUMMYX[!].
  60.  
  61.  
  62.  - Variable: GENINDEX
  63.      default: [I] is the alphabetic prefix used to generate the next
  64.      variable of summation when necessary.
  65.  
  66.  
  67.  - Variable: GENSUMNUM
  68.      [0] is the numeric suffix used to generate the next variable of
  69.      summation.  If it is set to FALSE then the index will consist only
  70.      of GENINDEX with no numeric suffix.
  71.  
  72.  
  73.  - Variable: INF
  74.      - real positive infinity.
  75.  
  76.  
  77.  - Variable: INFINITY
  78.      - complex infinity, an infinite magnitude of arbitrary phase
  79.      angle.  (See also INF and MINF.)
  80.  
  81.  
  82.  - Variable: INFOLISTS
  83.      default: [] a list of the names of all of the information lists in
  84.      MACSYMA. These are: LABELS - all bound C,D, and E labels.  VALUES
  85.      - all bound atoms, i.e. user variables, not MACSYMA Options or
  86.      Switches, (set up by : , :: , or functional binding).  FUNCTIONS -
  87.      all user defined functions (set up by f(x):=...).  ARRAYS -
  88.      declared and undeclared arrays (set up by : , :: , or :=...)
  89.      MACROS - any Macros defined by the user.  MYOPTIONS - all options
  90.      ever reset by the user (whether or not they get reset to their
  91.      default value).  RULES - user defined pattern matching and
  92.      simplification rules (set up by TELLSIMP, TELLSIMPAFTER, DEFMATCH,
  93.      or, DEFRULE.)  ALIASES - atoms which have a user defined alias
  94.      (set up by the ALIAS, ORDERGREAT, ORDERLESS functions or by
  95.      DECLAREing the atom a NOUN).  DEPENDENCIES - atoms which have
  96.      functional dependencies (set up by the DEPENDS or GRADEF
  97.      functions).  GRADEFS - functions which have user defined
  98.      derivatives (set up by the GRADEF function).  PROPS - atoms which
  99.      have any property other than those mentioned above, such as
  100.      atvalues, matchdeclares, etc.  as well as properties specified in
  101.      the DECLARE function.  LET_RULE_PACKAGES - a list of all the
  102.      user-defined let rule packages plus the special package
  103.      DEFAULT_LET_RULE_PACKAGE.  (DEFAULT_LET_RULE_PACKAGE is the name
  104.      of the rule package used when one is not explicitly set by the
  105.      user.)
  106.  
  107.  
  108.  - Function: INTEGERP (exp)
  109.      is TRUE if exp is an integer else FALSE.
  110.  
  111.  
  112.  - Variable: M1PBRANCH
  113.      default: [FALSE] - "principal branch for -1 to a power".
  114.      Quantities such as (-1)^(1/3) [i.e. "odd" rational exponent] and
  115.      (-1)^(1/4) [i.e. "even" rational exponent] are now handled as
  116.      indicated in the following chart:
  117.                        DOMAIN:REAL(default)
  118.           
  119.           (-1)^(1/3):      -1
  120.           (-1)^(1/4):   (-1)^(1/4)
  121.           
  122.                           DOMAIN:COMPLEX
  123.           M1PBRANCH:FALSE(default)   M1PBRANCH:TRUE
  124.           (-1)^(1/3)               1/2+%i*sqrt(3)/2
  125.           (-1)^(1/4)              sqrt(2)/2+%i*sqrt(2)/2
  126.  
  127.  - Function: NUMBERP (exp)
  128.      is TRUE if exp is an integer, a rational number, a floating point
  129.      number or a bigfloat else FALSE.
  130.  
  131.  
  132.  - Function: PROPERTIES (a)
  133.      will yield a list showing the names of all the properties
  134.      associated with the atom a.
  135.  
  136.  
  137.  - special symbol: PROPS
  138.      - atoms which have any property other than those explicitly
  139.      mentioned in INFOLISTS, such as atvalues, matchdeclares, etc. as
  140.      well as properties specified in the DECLARE function.
  141.  
  142.  
  143.  - Function: PROPVARS (prop)
  144.      yields a list of those atoms on the PROPS list which have the
  145.      property indicated by prop.  Thus PROPVARS(ATVALUE) will yield a
  146.      list of atoms which have atvalues.
  147.  
  148.  
  149.  - Function: PUT (a, p, i)
  150.      associates with the atom a the property p with the indicator i.
  151.      This enables the user to give an atom any arbitrary property.
  152.  
  153.  
  154.  - Function: QPUT (a, p, i)
  155.      is similar to PUT but it doesn't have its arguments evaluated.
  156.  
  157.  
  158.  - Function: REM (a, i)
  159.      removes the property indicated by i from the atom a.
  160.  
  161.  
  162.  - Function: REMOVE (args)
  163.      will remove some or all of the properties associated with
  164.      variables or functions.  REMOVE(a1, p1, a2, p2, ...)  removes the
  165.      property pi from the atom ai.  Ai and pi may also be lists as with
  166.      DECLARE.  Pi may be any property e.g.  FUNCTION, MODE_DECLARE,
  167.      etc.  It may also be TRANSFUN implying that the translated LISP
  168.      version of the function is to be removed.  This is useful if one
  169.      wishes to have the MACSYMA version of the function executed rather
  170.      than the translated version. Pi may also be OP or OPERATOR to
  171.      remove a syntax extension given to ai (see Appendix II).  If ai is
  172.      "ALL" then the property indicated by pi is removed from all atoms
  173.      which have it.  Unlike the more specific remove functions
  174.      (REMVALUE, REMARRAY, REMFUNCTION, and REMRULE) REMOVE does not
  175.      indicate when a given property is non-existent; it always returns
  176.      "DONE".
  177.  
  178.  
  179.  - Function: REMVALUE (name1, name2, ...)
  180.      removes the values of user variables (which can be subscripted)
  181.      from the system.  If name is ALL then the values of all user
  182.      variables are removed.  Values are those items given names by the
  183.      user as opposed to those which are automatically labeled by
  184.      MACSYMA as Ci, Di, or Ei.
  185.  
  186.  
  187.  - Function: RENAME (exp)
  188.      returns an expression equivalent to exp but with the dummy indices
  189.      in each term chosen from the set [!1,!2,...].  Each dummy index in
  190.      a product will be different; for a sum RENAME will try to make
  191.      each dummy index in a sum the same.  In addition, the indices will
  192.      be sorted alphanumerically.
  193.  
  194.  
  195.  - Function: RNCOMBINE (exp)
  196.      transforms exp by combining all terms of exp that have identical
  197.      denominators or denominators that differ from each other by
  198.      numerical factors only.  This is slightly different from the
  199.      behavior of COMBINE, which collects terms that have identical
  200.      denominators.  Setting PFEFORMAT:TRUE and using COMBINE will
  201.      achieve results similar to those that can be obtained with
  202.      RNCOMBINE, but RNCOMBINE takes the additional step of
  203.      cross-multiplying numerical denominator factors.  This results in
  204.      neater forms, and the possiblity of recognizing some
  205.      cancellations.  Bugs to ASB.
  206.  
  207.  
  208.  - Function: SCALARP (exp)
  209.      is TRUE if exp is a number, constant, or variable DECLAREd SCALAR,
  210.      or composed entirely of numbers, constants, and such variables,
  211.      but not containing matrices or lists.
  212.  
  213.  
  214.  - Function: SCALEFACTORS (coordinatetransform)
  215.      Here coordinatetransform evaluates to the form [[expression1,
  216.      expression2, ...], indeterminate1, indeterminat2, ...], where
  217.      indeterminate1, indeterminate2, etc. are the curvilinear
  218.      coordinate variables and where a set of rectangular Cartesian
  219.      components is given in terms of the curvilinear coordinates by
  220.      [expression1, expression2, ...].  COORDINATES is set to the vector
  221.      [indeterminate1, indeterminate2,...], and DIMENSION is set to the
  222.      length of this vector.  SF[1], SF[2], ..., SF[DIMENSION] are set
  223.      to the coordinate scale factors, and SFPROD is set to the product
  224.      of these scale factors.  Initially, COORDINATES is [X, Y, Z],
  225.      DIMENSION is 3, and SF[1]=SF[2]=SF[3]=SFPROD=1, corresponding to
  226.      3-dimensional rectangular Cartesian coordinates.  To expand an
  227.      expression into physical components in the current coordinate
  228.      system, there is a function with usage of the form
  229.  
  230.  
  231.  - Function: SETUP_AUTOLOAD (file,func1,...,funcN)
  232.      which takes two or more arguments: a file specification, and one
  233.      or more function names, "funcI", and which indicates that if a
  234.      call to "funcI" is made and "funcI" is not defined, that the file
  235.      specified by "file" is to be automatically loaded in via LOAD,
  236.      which file should contain a definition for "funcI".  (This is the
  237.      process by which calling e.g.  INTEGRATE in a fresh MACSYMA causes
  238.      various files to be loaded in.)  As with the other file-handling
  239.      commands in MACSYMA, the arguments to SETUP_AUTOLOAD are not
  240.      evaluated.  Example: SETUP_AUTOLOAD("bessel")$ J1(0.0); .  Note:
  241.      SETUP_AUTOLOAD does not work for array functions.
  242.  
  243.  
  244. 
  245. File: maxima.info,  Node: Rules and Patterns,  Next: Lists,  Prev: Miscellaneous Options,  Up: Top
  246.  
  247. Rules and Patterns
  248. ******************
  249.  
  250. * Menu:
  251.  
  252. * Introduction to Rules and Patterns::
  253. * Definitions for Rules and Patterns::
  254.  
  255. 
  256. File: maxima.info,  Node: Introduction to Rules and Patterns,  Next: Definitions for Rules and Patterns,  Prev: Rules and Patterns,  Up: Rules and Patterns
  257.  
  258. Introduction to Rules and Patterns
  259. ==================================
  260.  
  261.    This section discusses user defined pattern matching and
  262. simplification rules (set up by TELLSIMP, TELLSIMPAFTER, DEFMATCH, or,
  263. DEFRULE.)  You may affect the main simplification procedures, or else
  264. have your rules applied explicityly using APPLY1 and APPLY2.     There
  265. are additional mechanisms for polynomials rules under TELLRAT, and for
  266. commutative and non commutative algebra in chapter on AFFINE.
  267.  
  268. 
  269. File: maxima.info,  Node: Definitions for Rules and Patterns,  Prev: Introduction to Rules and Patterns,  Up: Rules and Patterns
  270.  
  271. Definitions for Rules and Patterns
  272. ==================================
  273.  
  274.  - Function: APPLY1 (exp, rule1, ..., rulen)
  275.      repeatedly applies the first rule to exp until it fails, then
  276.      repeatedly applies the same rule to all subexpressions of exp,
  277.      left-to-right, until the first rule has failed on all
  278.      subexpressions.  Call the result of transforming exp in this
  279.      manner exp'.  Then the second rule is applied in the same fashion
  280.      starting at the top of exp'.  When the final rule fails on the
  281.      final subexpression, the application is finished.
  282.  
  283.  
  284.  - Function: APPLY2 (exp, rule1, ..., rulen)
  285.      differs from APPLY1 in that if the first rule fails on a given
  286.      subexpression, then the second rule is repeatedly applied, etc.
  287.      Only if they all fail on a given subexpression is the whole set of
  288.      rules repeatedly applied to the next subexpression.  If one of the
  289.      rules succeeds, then the same subexpression is reprocessed,
  290.      starting with the first rule.  MAXAPPLYDEPTH[10000] is the maximum
  291.      depth to which APPLY1 and APPLY2 will delve.
  292.  
  293.  
  294.  - Function: APPLYB1 (exp, rule1, ..., rulen)
  295.      is similar to APPLY1 but works from the "bottom up" instead of
  296.      from the "top down".  That is, it processes the smallest
  297.      subexpression of exp, then the next smallest, etc.
  298.      MAXAPPLYHEIGHT[10000] - is the maximum height to which APPLYB1 will
  299.      reach before giving up.
  300.  
  301.  
  302.  - Variable: CURRENT_LET_RULE_PACKAGE
  303.      default:[DEFAULT_LET_RULE_PACKAGE] - the name of the rule package
  304.      that is presently being used.  The user may reset this variable to
  305.      the name of any rule package previously defined via the LET
  306.      command.  Whenever any of the functions comprising the let package
  307.      are called with no package name the value of
  308.           CURRENT_LET_RULE_PACKAGE
  309.      is used.  If a call such as LETSIMP(expr,rule_pkg_name); is made,
  310.      the rule package rule_pkg_name is used for that LETSIMP command
  311.      only, i.e.  the value of CURRENT_LET_RULE_PACKAGE is not changed.
  312.  
  313.  
  314.  - Variable: DEFAULT_LET_RULE_PACKAGE
  315.      - the name of the rule package used when one is not explicitly set
  316.      by the user with LET or by changing the value of
  317.      CURRENT_LET_RULE_PACKAGE.
  318.  
  319.  
  320.  - Function: DEFMATCH (progname, pattern, parm1, ..., parmn)
  321.      creates a function of n+1 arguments with the name progname which
  322.      tests an expression to see if it can match a particular pattern.
  323.      The pattern is some expression containing pattern variables and
  324.      parameters.  The parms are given explicitly as arguments to
  325.      DEFMATCH while the pattern variables (if supplied) were given
  326.      implicitly in a previous MATCHDECLARE function.  The first
  327.      argument to the created function progname, is an expression to be
  328.      matched against the "pattern" and the other n arguments are the
  329.      actual variables occurring in the expression which are to take the
  330.      place of dummy variables occurring in the "pattern".  Thus the
  331.      parms in the DEFMATCH are like the dummy arguments to the
  332.      SUBROUTINE statement in FORTRAN.  When the function is "called"
  333.      the actual arguments are substituted.  For example:
  334.           (C1)  NONZEROANDFREEOF(X,E):=  IF E#0 AND FREEOF(X,E)
  335.                       THEN TRUE ELSE FALSE$
  336.           (IS(E#0 AND FREEOF(X,E)) is an  equivalent function
  337.           definition)
  338.           (C2)  MATCHDECLARE(A,NONZEROANDFREEOF(X),B,FREEOF(X))$
  339.           (C3)  DEFMATCH(LINEAR,A*X+B,X)$
  340.               This has caused the function LINEAR(exp,var1) to be defined.  It
  341.  
  342.      tests exp to see if it is of the form A*var1+B where A and B do not
  343.      contain var1 and A is not zero.  DEFMATCHed functions return (if
  344.      the match is successful) a list of equations whose left sides are
  345.      the pattern variables and parms and whose right sides are the
  346.      expressions which the pattern variables and parameters matched.
  347.      The pattern variables, but not the parameters, are set to the
  348.      matched expressions.  If the match fails, the function returns
  349.      FALSE.  Thus LINEAR(3*Z+(Y+1)*Z+Y**2,Z) would return [B=Y**2,
  350.      A=Y+4, X=Z].  Any variables not declared as pattern variables in
  351.      MATCHDECLARE or as parameters in DEFMATCH which occur in pattern
  352.      will match only themselves so that if the third argument to the
  353.      DEFMATCH in (C4) had been omitted, then LINEAR would only match
  354.      expressions linear in X, not in any other variable.      A pattern
  355.      which contains no parameters or pattern variables returns TRUE if
  356.      the match succeeds.  Do EXAMPLE(DEFMATCH); for more examples.
  357.  
  358.  
  359.  - Function: DEFRULE (rulename, pattern, replacement)
  360.      defines and names a replacement rule for the given pattern.  If
  361.      the rule named rulename is applied to an expression (by one of the
  362.      APPLY functions below), every subexpression matching the pattern
  363.      will be replaced by the replacement.  All variables in the
  364.      replacement which have been assigned values by the pattern match
  365.      are assigned those values in the replacement which is then
  366.      simplified.  The rules themselves can be treated as functions
  367.      which will transform an expression by one operation of the pattern
  368.      match and replacement.  If the pattern fails, the original
  369.      expression is returned.
  370.  
  371.  
  372.  - Function: DISPRULE (rulename1, rulename2, ...)
  373.      will display rules with the names rulename1, rulename2, as were
  374.      given by DEFRULE, TELLSIMP, or TELLSIMPAFTER or a pattern defined
  375.      by DEFMATCH.  For example, the first rule modifying SIN will be
  376.      called SINRULE1.  DISPRULE(ALL); will display all rules.
  377.  
  378.  
  379.  - Function: LET (prod, repl, predname, arg1, arg2, ..., argn)
  380.      defines a substitution rule for LETSIMP such that prod gets
  381.      replaced by repl.  prod is a product of positive or negative
  382.      powers of the following types of terms:
  383.         *     (1) Atoms which LETSIMP will search for literally unless
  384.           previous to calling LETSIMP the MATCHDECLARE function is used
  385.           to associate a predicate with the atom.  In this case LETSIMP
  386.           will match the atom to any term of a product satisfying the
  387.           predicate.
  388.  
  389.         *     (2) Kernels such as SIN(X), N!, F(X,Y), etc.  As with
  390.           atoms above LETSIMP will look for a literal match unless
  391.           MATCHDECLARE is used to associate a predicate with the
  392.           argument of the kernel.  A term to a positive power will only
  393.           match a term having at least that power in the expression
  394.           being LETSIMPed.  A term to a negative power on the other
  395.           hand will only match a term with a power at least as
  396.           negative.  In the case of negative powers in "product" the
  397.           switch LETRAT must be set to TRUE (see below).  If a
  398.           predicate is included in the LET function followed by a list
  399.           of arguments, a tentative match (i.e. one that would be
  400.           accepted if the predicate were omitted) will be accepted only
  401.           if predname(arg1',...,argn') evaluates to TRUE where argi' is
  402.           the value matched to argi.  The argi may be the name of any
  403.           atom or the argument of any kernel appearing in prod.  repl
  404.           may be any rational expression.  If any of the atoms or
  405.           arguments from prod appear in repl the appropriate
  406.           substitutions will be made.
  407.          LETRAT[FALSE] when FALSE, LETSIMP will simplify the numerator
  408.      and denominator of expr independently and return the result.
  409.      Substitutions such as N!/N goes to (N-1)!  will fail.  To handle
  410.      such situations LETRAT should be set to TRUE, then the numerator,
  411.      denominator, and their quotient will be simplified in that order.
  412.         These substitution functions allow you to work with several
  413.      rulepackages at once. Each rulepackage can contain any number of
  414.      LETed rules and is referred to by a user supplied name.  To insert
  415.      a rule into the rulepackage name, do
  416.      LET([prod,repl,pred,arg1,...],name).  To apply the rules in
  417.      rulepackage name, do LETSIMP(expr, name).  The function
  418.      LETSIMP(expr,name1,name2,...)  is equivalent to doing
  419.      LETSIMP(expr,name1) followed by LETSIMP(%,name2) etc.
  420.      CURRENT_LET_RULE_PACKAGE is the name of the rule package that is
  421.      presently being used.  The user may reset this variable to the
  422.      name of any rule package previously defined via the LET command.
  423.      Whenever any of the functions comprising the let package are
  424.      called with no package name the value of CURRENT_LET_RULE_PACKAGE
  425.      is used.  If a call such as LETSIMP(expr,rule_pkg_name); is made,
  426.      the rule package rule_pkg_name is used for that LETSIMP command
  427.      only, i.e.  the value of CURRENT_LET_RULE_PACKAGE is not changed.
  428.      There is a DEFAULT_LET_RULE_PACKAGE which is assumed when no other
  429.      name is supplied to any of the functions.  Whenever a LET includes
  430.      a rulepackage name that is used as the CURRENT_LET_RULE_PACKAGE.
  431.  
  432.  
  433.  - Variable: LETRAT
  434.      default: [FALSE] - when FALSE, LETSIMP will simplify the numerator
  435.      and denominator of expr independently and return the result.
  436.      Substitutions such as N!/N goes to (N-1)! will fail.  To handle
  437.      such situations LETRAT should be set to TRUE, then the numerator,
  438.      denominator, and their quotient will be simplified in that order.
  439.  
  440.  
  441.  - Function: LETRULES ()
  442.      displays the rules in the current rulepackage.  LETRULES(name)
  443.      displays the rules in the named rulepackage.  The current
  444.      rulepackage is the value of
  445.           CURRENT_LET_RULE_PACKAGE
  446.      The initial value of the rules is
  447.           DEFAULT_LET_RULE_PACKAGE
  448.  
  449.  
  450.  - Function: LETSIMP (exp)
  451.      will continually apply the substitution rules previously defined
  452.      by the function LET until no further change is made to exp.
  453.      LETSIMP(expr,rule_pkg_name); will cause the rule package
  454.      rule_pkg_name to be used for that LETSIMP command only, i.e.  the
  455.      value of CURRENT_LET_RULE_PACKAGE is not changed.
  456.  
  457.  
  458.  - Variable: LET_RULE_PACKAGES
  459.      default:[DEFAULT_LET_RULE_PACKAGE] - The value of
  460.      LET_RULE_PACKAGES is a list of all the user-defined let rule
  461.      packages plus the special package
  462.           DEFAULT_LET_RULE_PACKAGE
  463.      This is the name of the rule package used when one is not
  464.      explicitly set by the user.
  465.  
  466.  
  467.  - Function: MATCHDECLARE (patternvar, predicate, ...)
  468.      associates a predicate with a pattern variable so that the
  469.      variable will only match expressions for which the predicate is
  470.      not FALSE.  (The matching is accomplished by one of the functions
  471.      described below).  For example after
  472.           MATCHDECLARE(Q,FREEOF(X,%E))
  473.      is executed, Q will match any expression not containing X or %E.
  474.      If the match succeeds then the variable is set to the matched
  475.      expression.  The predicate (in this case FREEOF) is written
  476.      without the last argument which should be the one against which
  477.      the pattern variable is to be tested.  Note that the patternvar
  478.      and the arguments to the predicate are evaluated at the time the
  479.      match is performed.  The odd numbered argument may also be a list
  480.      of pattern variables all of which are to have the associated
  481.      predicate.  Any even number of arguments may be given.  For
  482.      pattern matching, predicates refer to functions which are either
  483.      FALSE or not FALSE (any non FALSE value acts like TRUE).
  484.      MATCHDECLARE(var,TRUE) will permit var to match any expression.
  485.  
  486.  
  487.  - Function: MATCHFIX
  488.      - MATCHFIX operators are used to denote functions of any number of
  489.      arguments which are passed to the function as a list.  The
  490.      arguments occur between the main operator and its "matching"
  491.      delimiter.  The MATCHFIX("x",...) function is a syntax extension
  492.      function which declares x to be a MATCHFIX operator.   The default
  493.      binding power is 180, and the ARGS inside may be anything.
  494.  
  495.  
  496.           (C1) matchfix("|","|");
  497.           
  498.           (D1)                       "|"
  499.           (C2) |a|+b;
  500.           
  501.           (D2)                    b + (|a|)
  502.           (C3) |(a,b)|;
  503.           
  504.           (D3)                       |b|
  505.           (C4) |[a,b]|;
  506.           
  507.           (D4)                    |[a, b]|
  508.           
  509.           (C9) |x|:=IF NUMBERP(x) THEN ABS(x)
  510.                   ELSE (IF LISTP(x) AND APPLY("and",MAP(NUMBERP,x))
  511.                     THEN SUM(x[i]^2,i,1,LENGTH(x))^0.5 ELSE BUILDQ([u:x],|u|))$
  512.           
  513.           (C10) |[1,2,3]|;
  514.           
  515.           (D10)                    3.741657386773941
  516.           
  517.           (C18) |-7|;
  518.           
  519.           (D18)                        7
  520.           (C19) |[a,b]|;
  521.           
  522.           (D19)                    |[a, b]|
  523.  
  524.  
  525.  - Function: REMLET (prod, name)
  526.      deletes the substitution rule, prod -> repl, most recently defined
  527.      by the LET function.  If name is supplied the rule is deleted from
  528.      the rule package name.  REMLET() and REMLET(ALL) delete all
  529.      substitution rules from the current rulepackage. If the name of a
  530.      rulepackage is supplied, e.g. REMLET(ALL,name), the rulepackage,
  531.      name, is also deleted.  If a substitution is to be changed using
  532.      the same product, REMLET need not be called, just redefine the
  533.      substitution using the same product (literally) with the LET
  534.      function and the new replacement and/or predicate name.  Should
  535.      REMLET(product) now be called the original substitution rule will
  536.      be revived.
  537.  
  538.  
  539.  - Function: REMRULE (function, rulename)
  540.      will remove a rule with the name rulename from the function which
  541.      was placed there by DEFRULE, DEFMATCH, TELLSIMP, or TELLSIMPAFTER.
  542.      If rule-name is ALL, then all rules will be removed.
  543.  
  544.  
  545.  - Function: TELLSIMP (pattern, replacement)
  546.      is similar to TELLSIMPAFTER but places new information before old
  547.      so that it is applied before the built-in simplification rules.
  548.      TELLSIMP is used when it is important to modify the expression
  549.      before the simplifier works on it, for instance if the simplifier
  550.      "knows" something about the expression, but what it returns is not
  551.      to your liking.  If the simplifier "knows" something about the
  552.      main operator of the expression, but is simply not doing enough for
  553.      you, you probably want to use TELLSIMPAFTER.  The pattern may not
  554.      be a sum, product, single variable, or number.  RULES is a list of
  555.      names having simplification rules added to them by DEFRULE,
  556.      DEFMATCH, TELLSIMP, or TELLSIMPAFTER.  Do EXAMPLE(TELLSIMP); for
  557.      examples.
  558.  
  559.  
  560.  - Function: TELLSIMPAFTER (pattern, replacement)
  561.      defines a replacement for pattern which the MACSYMA simplifier
  562.      uses after it applies the built-in simplification rules.  The
  563.      pattern may be anything but a single variable or a number.
  564.  
  565.  
  566. 
  567. File: maxima.info,  Node: Lists,  Next: Function Definition,  Prev: Rules and Patterns,  Up: Top
  568.  
  569. Lists
  570. *****
  571.  
  572. * Menu:
  573.  
  574. * Introduction to Lists::
  575. * Definitions for Lists::
  576.  
  577. 
  578. File: maxima.info,  Node: Introduction to Lists,  Next: Definitions for Lists,  Prev: Lists,  Up: Lists
  579.  
  580. Introduction to Lists
  581. =====================
  582.  
  583.    Lists are the basic building block for maxima and lisp.   All data
  584. types other than arrays, hash tables, numbers are represented as lisp
  585. lists, These lisp lists have the form
  586.      ((mplus) $A 2)
  587.  
  588. to indicate an expression `A+2'.   At maxima level one would see the
  589. infix notation `A+2'.   Maxima also has lists which are printed as
  590.      [1, 2, 7, x+y]
  591.  
  592. for a list with 4 elements.   Internally this corresponds to a lisp list
  593. of the form
  594.      ((mlist) 1  2  7  ((mplus)  $X $Y ))
  595.  
  596. The flag which denotes the type field of the maxima expression is a list
  597. itself, since after it has been through the simplifier the list would
  598. become
  599.      ((mlist simp) 1 2 7 ((mplus simp) $X $Y))
  600.  
  601. 
  602. File: maxima.info,  Node: Definitions for Lists,  Prev: Introduction to Lists,  Up: Lists
  603.  
  604. Definitions for Lists
  605. =====================
  606.  
  607.  - Function: APPEND (list1, list2, ...)
  608.      returns a single list of the elements of list1 followed by the
  609.      elements of list2,...  APPEND also works on general expressions,
  610.      e.g. APPEND(F(A,B), F(C,D,E)); -> F(A,B,C,D,E).  Do
  611.      EXAMPLE(APPEND); for an example.
  612.  
  613.  
  614.  - Function: ASSOC (exp)
  615.      This function searches for the key in the left hand side of the
  616.      input list of the form [x,y,z...] where each of the list elements
  617.      is a expression of a binary operand and 2 elements.  For example
  618.      x=1, 2^3, [a,b] etc.  The key checked againts the first operand
  619.      and and returns the second operand if the key is found.  If the
  620.      key is not found it either returns the default value if supplied or
  621.      false.
  622.  
  623.  - Function: ATOM (exp)
  624.      is TRUE if exp is atomic (i.e. a number or name) else FALSE.  Thus
  625.      ATOM(5) is TRUE while ATOM(A[1]) and ATOM(SIN(X)) are FALSE.
  626.      (Assuming A[1] and X are unbound.)
  627.  
  628.  
  629.  - Function: CONS (exp, list)
  630.      returns a new list constructed of the element exp as its first
  631.      element, followed by the elements of list.  CONS also works on
  632.      other expressions, e.g. CONS(X, F(A,B,C));  ->  F(X,A,B,C).
  633.  
  634.  
  635.  - Function: COPYLIST (L)
  636.      creates a copy of the list L.
  637.  
  638.  
  639.  - Function: DELETE (exp1, exp2)
  640.      removes all occurrences of exp1 from exp2.  Exp1 may be a term of
  641.      exp2 (if it is a sum) or a factor of exp2 (if it is a product).
  642.           (C1)  DELETE(SIN(X),X+SIN(X)+Y);
  643.           (D1)               Y + X
  644.      DELETE(exp1, exp2, integer) removes the first integer occurrences
  645.      of exp1 from exp2.  Of course, if there are fewer than integer
  646.      occurrences of exp1 in exp2 then all occurrences will be deleted.
  647.  
  648.  
  649.  - Function: ENDCONS (exp, list)
  650.      returns a new list consisting of the elements of list followed by
  651.      exp.  ENDCONS also works on general expressions, e.g.  ENDCONS(X,
  652.      F(A,B,C));  ->  F(A,B,C,X).
  653.  
  654.  
  655.  - Function: EVERY (exp)
  656.      This function takes a list, or a positive number of arguments and
  657.      returns true if all its arguments are not false.
  658.  
  659.  
  660.  - Function: FIRST (exp) SECOND (exp) .. TENTH (exp)
  661.      yields the first part of exp which may result in the first element
  662.      of a list, the first row of a matrix, the first term of a sum,
  663.      etc.  Note that FIRST and its related functions, REST and LAST,
  664.      work on the form of exp which is displayed not the form which is
  665.      typed on input.  If the variable INFLAG [FALSE] is set to TRUE
  666.      however, these functions will look at the internal form of exp.
  667.      Note that the simplifier re-orders expressions.  Thus FIRST(X+Y)
  668.      will be X if INFLAG is TRUE and Y if INFLAG is FALSE.  (FIRST(Y+X)
  669.      gives the same results).  The functions SECOND .. TENTH yield the
  670.      second through the tenth part of their input argument.
  671.  
  672.  
  673.  - Function: FLATTEN(exp)
  674.      Takes a list of the form [[1,2],[3,4]] and returns [1,2,3,4].
  675.  
  676.  
  677.  - Function: GET (a, i)
  678.      retrieves the user property indicated by i associated with atom a
  679.      or returns FALSE if a doesn't have property i.
  680.           (C1) PUT(%E,'TRANSCENDENTAL,'TYPE);
  681.           (D1)                     TRANSCENDENTAL
  682.           (C2) PUT(%PI,'TRANSCENDENTAL,'TYPE)$
  683.           (C3) PUT(%I,'ALGEBRAIC,'TYPE)$
  684.           (C4) TYPEOF(EXP) := BLOCK([Q],
  685.                                   IF NUMBERP(EXP)
  686.                                   THEN RETURN('ALGEBRAIC),
  687.                                   IF NOT ATOM(EXP)
  688.                                   THEN RETURN(MAPLIST('TYPEOF, EXP)),
  689.                                   Q : GET(EXP, 'TYPE),
  690.                                   IF Q=FALSE
  691.                       THEN ERRCATCH(ERROR(EXP,"is not numeric.")) ELSE Q)$
  692.           (C5) TYPEOF(2*%E+X*%PI);
  693.           X is not numeric.
  694.           (D5)          [[TRANSCENDENTAL, []], [ALGEBRAIC, TRANSCENDENTAL]]
  695.           (C6) TYPEOF(2*%E+%PI);
  696.           (D6)             [TRANSCENDENTAL, [ALGEBRAIC, TRANSCENDENTAL]]
  697.  
  698.  - Function: LAST (exp)
  699.      yields the last part (term, row, element, etc.) of the exp.
  700.  
  701.  
  702.  - Function: LENGTH (exp)
  703.      gives (by default) the number of parts in the external (displayed)
  704.      form of exp.  For lists this is the number of elements, for
  705.      matrices it is the number of rows, and for sums it is the number
  706.      of terms. (See DISPFORM).  The LENGTH command is affected by the
  707.      INFLAG switch [default FALSE].  So, e.g. LENGTH(A/(B*C)); gives 2
  708.      if INFLAG is FALSE (Assuming EXPTDISPFLAG is TRUE), but 3 if
  709.      INFLAG is TRUE (the internal representation is essentially
  710.      A*B^-1*C^-1).
  711.  
  712.  
  713.  - Variable: LISTARITH
  714.      default: [TRUE] - if FALSE causes any arithmetic operations with
  715.      lists to be suppressed; when TRUE, list-matrix operations are
  716.      contagious causing lists to be converted to matrices yielding a
  717.      result which is always a matrix.  However, list-list operations
  718.      should return lists.
  719.  
  720.  
  721.  - Function: LISTP (exp)
  722.      is TRUE if exp is a list else FALSE.
  723.  
  724.  
  725.  - Function: MAKELIST (exp,var,lo,hi)
  726.      returns a list as value.  MAKELIST may be called as
  727.      MAKELIST(exp,var,lo,hi) ["lo" and "hi" must be integers], or as
  728.      MAKELIST(exp,var,list).  In the first case MAKELIST is analogous to
  729.      SUM, whereas in the second case MAKELIST is similar to MAP.
  730.      Examples:
  731.              MAKELIST(CONCAT(X,I),I,1,6) yields [X1,X2,X3,X4,X5,X6]
  732.              MAKELIST(X=Y,Y,[A,B,C]) yields [X=A,X=B,X=C]
  733.  
  734.  
  735.  - Function: MEMBER (exp, list)
  736.      returns TRUE if exp occurs as a member of list (not within a
  737.      member).  Otherwise FALSE is returned.  Member also works on
  738.      non-list expressions, e.g. MEMBER(B, F(A,B,C));  ->  TRUE.
  739.  
  740.  
  741.  - Function: REST (exp, n)
  742.      yields exp with its first n elements removed if n is positive and
  743.      its last -n elements removed if n is negative.  If n is 1 it may
  744.      be omitted.  Exp may be a list, matrix, or other expression.
  745.  
  746.  
  747.  - Function: REVERSE (list)
  748.      reverses the order of the members of the list (not the members
  749.      themselves).  REVERSE also works on general expressions, e.g.
  750.      REVERSE(A=B); gives B=A.  REVERSE default: [FALSE] - in the
  751.      Plotting functions, if TRUE cause a left-handed coordinate system
  752.      to be assumed.
  753.  
  754.  
  755. 
  756. File: maxima.info,  Node: Function Definition,  Next: Program Flow,  Prev: Lists,  Up: Top
  757.  
  758. Function Definition
  759. *******************
  760.  
  761. * Menu:
  762.  
  763. * Introduction to Function Definition::
  764. * FUNCTION::
  765. * MACROS::
  766. * OPTIMIZATION::
  767. * Definitions for Function Definition::
  768.  
  769. 
  770. File: maxima.info,  Node: Introduction to Function Definition,  Next: FUNCTION,  Prev: Function Definition,  Up: Function Definition
  771.  
  772. Introduction to Function Definition
  773. ===================================
  774.  
  775. 
  776. File: maxima.info,  Node: FUNCTION,  Next: MACROS,  Prev: Introduction to Function Definition,  Up: Function Definition
  777.  
  778. FUNCTION
  779. ========
  780.  
  781.    - To define a function in MACSYMA you use the := operator.  E.g.
  782.      F(X):=SIN(X)
  783.  
  784. defines a function F.  Anonmyous functions may also be created using
  785. LAMBDA.  For example
  786.      lambda([i,j], ... )
  787.  
  788. can be used instead of F where
  789.      F(I,J):=BLOCK([], ... );
  790.      MAP(LAMBDA([I],I+1),L)
  791.  
  792. would return a list with 1 added to each term.
  793.  
  794.    You may also define a function with a variable number of arguments,
  795. by having a final argument which is assigned to a list of the extra
  796. arguments:
  797.  
  798.      (C8) f([u]):=u;
  799.      (C9) f(1,2,3,4);
  800.      (D9)                  [1, 2, 3, 4]
  801.      (C11) f(a,b,[u]):=[a,b,u];
  802.      (C12) f(1,2,3,4,5,6);
  803.      (D12)                  [1, 2, [3, 4, 5, 6]]
  804.  
  805.    The right hand side of a function is an expression.  Thus if you
  806. want a sequence of expressions, you do
  807.  
  808.      f(x):=(expr1,expr2,....,exprn);
  809.    and the value of exprn is what is returned by the function.
  810.  
  811.    If you wish to make a `return' from some expression inside the
  812. function then you must use `block' and `return'.
  813.  
  814.      block([],expr1,...,if(a>10) then return(a),...exprn)
  815.    is itelf an expression, and so could take the place of the right
  816. hand side of a function definition.  Here it may happen that the return
  817. happens earlier than the last expression.
  818.  
  819.    The first `[]' in the block, may contain a list of variables and
  820. variable assignments, such as `[a:3,b,c:[]]', which would cause the
  821. three variables `a',`b',and `c' to not refer to their global values,
  822. but rather have these special values for as long as the code executes
  823. inside the `block', or inside functions called from inside the `block'.
  824. This is called dynamic binding, since the variables last from the
  825. start of the block to the time it exits.  Once you return from the
  826. `block', or throw out of it, the old values (if any) of the variables
  827. will be restored.   It is certainly a good idea to protect your
  828. variables in this way.   Note that the assignments in the block
  829. variables, are done in parallel.   This means, that if you had used
  830. `c:a' in the above, the value of `c' would have been the value of `a'
  831. at the time you just entered the block, but before `a' was bound.
  832. Thus doing something like
  833.  
  834.      block([a:a],expr1,... a:a+3,...exprn)
  835.    will protect the external value of `a' from being altered, but would
  836. let you access what that value was.   Thus the right hand side of the
  837. assignments, is evaluated in the entering context, before any binding
  838. occurs.  Using just `block([x],..' would cause the x to have itself as
  839. value, just as if it would have if you entered a fresh MAXIMA session.
  840.  
  841.    The actual arguments to a function are treated in exactly same way as
  842. the variables in a block.  Thus in
  843.  
  844.      f(x):=(expr1,...exprn);
  845.      and
  846.      f(1);
  847.    we would have a similar context for evaluation of the expressions as
  848. if we had done
  849.      block([x:1],expr1,...exprn)
  850.  
  851.    Inside functions, when the right hand side of a definition, may be
  852. computed at runtime, it is useful to use `define' and possibly `buildq'.
  853.  
  854. 
  855. File: maxima.info,  Node: MACROS,  Next: OPTIMIZATION,  Prev: FUNCTION,  Up: Function Definition
  856.  
  857. MACROS
  858. ======
  859.  
  860.  - Function: BUILDQ ([varlist],expression);
  861.      EXPRESSION is any single MAXIMA expression and  VARLIST is a list
  862.      of elements of the form `<atom>' or `<atom>:<value>'
  863.  
  864. Semantics
  865. ---------
  866.  
  867.    The <value>s in the <varlist> are evaluated left to right (the syntax
  868. <atom> is equivalent to <atom>:<atom>).  then these values are
  869. substituted into <expression> in parallel.  If any <atom> appears as a
  870. single argument to the special form SPLICE (i.e. SPLICE(<atom>) ) inside
  871. <expression>, then the value associated with that <atom> must be a
  872. macsyma list, and it is spliced into <expression> instead of
  873. substituted.
  874.  
  875. SIMPLIFICATION
  876. --------------
  877.  
  878.    The arguments to BUILDQ need to be protected from simplification
  879. until the substitutions have been carried out.  This code should affect
  880. that by using `''.
  881.  
  882.    `buildq' can be useful for building functions on the fly.  One of
  883. the powerful things about MAXIMA is that you can have your functions
  884. define other functions to help solve the problem.  Further below we
  885. discuss building a recursive function, for a series solution.   This
  886. defining of functions inside functions usually uses `define', which
  887. evaluates its arguments.  A number of examples are included under
  888. `splice'.
  889.  
  890.  - Function: SPLICE (atom)
  891.      This is used with buildq to construct a list. This is handy for
  892.      making argument lists, in conjunction with BUILDQ
  893.  
  894.           MPRINT([X]) ::= BUILDQ([U : x],
  895.             if (debuglevel > 3) print(splice(u)));
  896.  
  897.      Including a call like
  898.           MPRINT("matrix is ",MAT,"with length",LENGTH(MAT))
  899.      is equivalent to putting in the line
  900.  
  901.           IF DEBUGLEVEL > 3
  902.             THEN PRINT("matrix is ",MAT,"with length",
  903.                         LENGTH(MAT))
  904.  
  905.      A more non trivial example would try to display the variable values
  906.      AND their names.
  907.           MSHOW(A,B,C)
  908.  
  909.      should become
  910.  
  911.           PRINT('A,"=",A,",",'B,"=",B,", and",'C,"=",C)
  912.  
  913.      so that if it occurs as a line in a program we can print values.
  914.  
  915.           (C101) foo(x,y,z):=mshow(x,y,z);
  916.           (C102) foo(1,2,3);
  917.           X = 1 , Y = 2 , and Z = 3
  918.  
  919.      The actual definition of mshow is the following.   Note how buildq
  920.      lets you build 'QUOTED' structure, so that the  `'u' lets you get
  921.      the variable name.  Note that in macros, the RESULT is a piece of
  922.      code which will then be substituted for the macro and evaluated.
  923.  
  924.           MSHOW([lis])::=BLOCK([ans:[],N:LENGTH(lis)],
  925.                  FOR i THRU N DO
  926.                      (ans:APPEND(ans,
  927.                          BUILDQ([u:lis[i]],
  928.                             ['u,"=",u])),
  929.                   IF i < N
  930.                       THEN ans
  931.                       :APPEND(ans,
  932.                           IF i < N-1 THEN [","]
  933.                               ELSE [", and"])),
  934.                  BUILDQ([U:ans],PRINT(SPLICE(u))))
  935.  
  936.      The splice also works to put arguments into algebraic operations:
  937.  
  938.           (C108) BUILDQ([A:'[B,C,D]],+SPLICE(A));
  939.           (D108) D+C+B
  940.      Note how the simplification only occurs AFTER the substitution,
  941.      The operation applying to the splice in the first cae is the `+'
  942.      while in the second it is the `*', yet logically you might thing
  943.      `splice(a)+splice(A)' could be replaced by `2*splice(A)'.   No
  944.      simplification takes place with the buildq To understand what
  945.      SPLICE is doing with the algebra you must understand that for
  946.      MAXIMA, a formula an operation like `A+B+C' is really internally
  947.      similar to `+(A,B,C)', and similarly for multiplication.  Thus
  948.      `*(2,B,C,D)' is `2*B*C*D'
  949.  
  950.           (C114) BUILDQ([A:'[B,C,D]],+SPLICE(A));
  951.           (D114) D+C+B
  952.           
  953.           (C111) BUILDQ([A:'[B,C,D]],SPLICE(A)+SPLICE(A));
  954.           (D111) 2*D+2*C+2*B
  955.             but
  956.           (C112) BUILDQ([A:'[B,C,D]],2*SPLICE(A));
  957.           (D112) 2*B*C*D
  958.  
  959.      Finally the buildq can be invaluable for building recursive
  960.      functions.  Suppose your program is solving a differential
  961.      equation using the series method, and has determined that it needs
  962.      to build a recursion relation
  963.           F[N]:=(-((N^2-2*N+1)*F[N-1]+F[N-2]+F[N-3])/(N^2-N))
  964.      and it must do this on the fly inside your function.  Now you
  965.      would really like to add `expand'.
  966.           F[N]:=EXPAND((-((N^2-2*N+1)*F[N-1]+F[N-2]+F[N-3])
  967.             /(N^2-N)));
  968.      but how do you build this code.  You want the `expand' to happen
  969.      each time the function runs, NOT before it.
  970.           kill(f),
  971.           val:(-((N^2-2*N+1)*F[N-1]+F[N-2]+F[N-3])/(N^2-N)),
  972.           define(f[n],buildq([u:val],expand(u))),
  973.      does the job.   This might be useful, since when you do
  974.           With the Expand
  975.           (C28) f[6];
  976.           (D28) -AA1/8-13*AA0/180
  977.      where as without it is kept unsimplified, and even after 6 terms
  978.      it becomes:
  979.           (C25) f[6];
  980.           (D25) (5*(-4*(-3*(-2*(AA1+AA0)+AA1+AA0)/2
  981.                   -(AA1+AA0)/2+AA1)
  982.               /3
  983.               -(-2*(AA1+AA0)+AA1+AA0)/6+(-AA1-AA0)/2)
  984.                 /4
  985.                 +(-3*(-2*(AA1+AA0)+AA1+AA0)/2
  986.                  -(AA1+AA0)/2+AA1)
  987.                  /12-(2*(AA1+AA0)-AA1-AA0)/6)
  988.                 /30
  989.      The expression quickly becomes complicated if not simplified at
  990.      each stage, so the simplification must be part of the definition.
  991.      Hence the `buildq' is useful for building the form.
  992.  
  993. 
  994. File: maxima.info,  Node: OPTIMIZATION,  Next: Definitions for Function Definition,  Prev: MACROS,  Up: Function Definition
  995.  
  996. OPTIMIZATION
  997. ============
  998.  
  999.    The optimu files no longer exist in Maxima.  The documentation is
  1000. left here for historical purposes.
  1001.  
  1002.    When using TRANSLATE and generating code with MACSYMA, there are a
  1003. number of techniques which can save time and be helpful.  Do
  1004. DEMO("optimu.dem") for a demonstration.  In particular, the function
  1005. FLOATDEFUNK from TRANSL;OPTIMU FASL, creates a function definition from
  1006. a math-like expression, but it optimizes it (with OPTIMIZE) and puts in
  1007. the MODE_DECLAREations needed to COMPILE correctly. (This can be done
  1008. by hand, of course).  The demo will only run in a fresh macsyma.
  1009.  
  1010.